<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SilverMindMap.Core.View">
    
    <local:NullToHiddenConverter x:Key="_nullToHiddenConverter"/>
    <local:NotNullToHiddenConverter x:Key="_notNullToHiddenConverter"/>

    <Style TargetType="local:NodeControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:NodeControl">
                    <Button Command="{Binding ViewModel.SetAsRootNodeCommand, RelativeSource={RelativeSource TemplatedParent}}"
                                HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                        <Button.Template>
                            <ControlTemplate>
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>

                        <Border 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="5">
                        <Border.Background>
                            <SolidColorBrush Color="{Binding ViewModel.Node.BackgroundColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </Border.Background>
                        
                            <ContentPresenter x:Name="NodePresenter" 
                                              Content="{Binding ViewModel.Node, RelativeSource={RelativeSource TemplatedParent}}" 
                                              ContentTemplate="{Binding NodeTemplate, RelativeSource={RelativeSource TemplatedParent}}"
                                              Margin="8"/>
                        </Border>
                    </Button>                                            
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="NodeTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Grid>
                        <HyperlinkButton Content="{Binding Caption}" NavigateUri="{Binding Hyperlink}" FontWeight="Bold"
                                         Visibility="{Binding Hyperlink, Converter={StaticResource _nullToHiddenConverter}}">
                            <HyperlinkButton.Foreground>
                                <SolidColorBrush Color="{Binding ForegroundColor}"/>
                            </HyperlinkButton.Foreground>
                        </HyperlinkButton>
                        <TextBlock Text="{Binding Caption}" Visibility="{Binding Hyperlink, Converter={StaticResource _notNullToHiddenConverter}}">
                            <TextBlock.Foreground>
                                <SolidColorBrush Color="{Binding ForegroundColor}"/>
                            </TextBlock.Foreground>
                        </TextBlock>
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="local:LinkControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:LinkControl">
                    <Canvas x:Name="_layoutRoot">
                        <Line x:Name="_line" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}"
                              X1="0" Y1="0"/>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
